package com.duing.task;

import com.duing.dao.DataMapper;
import com.duing.entity.IllnessData;
import com.duing.util.GsonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Component
@EnableScheduling
public class DataTask {

    @Autowired
    private DataMapper dataMapper;

    @Scheduled(cron = "0 0/1 * * * ?")

    public void handleData() {
        SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
        System.out.println("当前时间：" + dateFormat.format(new Date()));

        dataMapper.deleteAll();
        List<IllnessData> list = GsonUtil.handleData();
        for (IllnessData illnessData : list) {
            dataMapper.insert(illnessData);
        }
        System.out.println(list.size() + "条数据更新完成");
    }
}
